package com.loong.user.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.user.common.backend.param.ManageResourceParam;
import com.loong.user.handler.ManageResourceHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 后台系统资源管理器
 * @Author: hzp
 * @Date: 2020-10-16 11:47
 */
@RestController
@RequestMapping("/manage/user/systemResource")
public class ManageResourceController extends BaseBackendController {
    @Resource
    private ManageResourceHandler manageResourceHandler;
    /**
     * @description: 保存后台系统资源
     * @param param
     * @return
     * @status done
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) ManageResourceParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->manageResourceHandler.save(param));
    }

    /**
     * @description: 更新后台系统资源
     * @param param
     * @return
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) ManageResourceParam param){
        return  handlerExecutor.execute(()->manageResourceHandler.update(param));
    }


    /**
     *
     *  @description: 获取后台系统资源树
     * @return
     */
    @PostMapping("queryTree")
    public Result queryAllResourceTree(Long roleId){

        return  handlerExecutor.execute(()->manageResourceHandler.queryAllResourceTree(roleId));
    }

    /**
     *根据id删除后台系统资源 递归删除
     * @param resourceIds
     */
    @PostMapping("delete")
    public Result deleteById(@RequestParam("resourceIds") List<Long> resourceIds){
        return handlerExecutor.execute(()->manageResourceHandler.deleteByIds(resourceIds));
    }

}
